package com.sky.mapper;

import com.sky.dto.IdDTO;
import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    void save(AddressBook addressBook);


    List<AddressBook> list(Long userId);

    AddressBook getDefault(Long userId);

    void update(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);

    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);

    @Select("select * from address_book where is_default = 1")
    AddressBook getDefaultAddress();

    @Update("update address_book set is_default = 0 where id = #{defaultId}")
    void updateDefault(Long isDefault);

    @Update("update address_book set is_default = 1 where id = #{id}")
    void setDefaultById(IdDTO id);
}
